(function(window){
    var funs = function() {
        return new funs.prototype.init()
    }

    funs.fn = funs.prototype = {
        init: function() {
            return this
        },
        keys: function(obj,callback,reverse) {
            if(!(Object.prototype.toString.call(obj) == '[object Object]' || !(Object.prototype.toString.call(obj) == '[object Array]'))) {
                throw new Error(`${obj}: may be Object or Array`)
                return;
            }

            let res = [];

            if(Object.prototype.toString.call(obj) == '[object Array]') {
                for(var i = 0;i < Object.length;i ++) {
                    res.push(i)
                }
            }else {

                for(var i in obj){
                    res.push(i)
                }
            }

            reverse && reverse == -1 ? res.reverse() : res

            return callback(res)
        },
        forEach: function(arr,callback) {
            if(!(Object.prototype.toString.call(arr) == '[object Array]')) {
                throw new Error(`${arr}: may be Array`)
                return;
            }

            var that = arr;
            var index,value,self,res;
            self = that;

            for(var i = 0; i < self.length;i ++) {
                index = i;
                value = self[i];
                res = callback(value,index,self)
            }

            return res
        },
        filter: function(arr, callback) {
            if(!(Object.prototype.toString.call(arr) == '[object Array]')) {
                throw new Error(`${arr}: may be Array`)
                return;
            }
            
            var that = arr;
            var index,value,self,res=[];
            self = that;
            
            for(var i = 0;i < self.length; i++) {
                if(callback(self[i],i,self)) {
                    res.push(self[i])
                }
            }

            return res
        }
    }
    
    funs.fn.init.prototype = funs.prototype;

    window.f = window.funs = funs(); 
})(window)